/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package business;

import data.DAO.PostDAO;
import data.DAO.services.PostDAOServices;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import model.entity.Post;

/**
 *
 * @author quanhungbang
 */
public class PostManageServiceImpl implements PostManageService {

    PostDAOServices pds = new PostDAO();

    @Override
    public List<Post> showAllPosts() {
        return pds.getAllPost();
    }

    @Override
    public boolean delete(int post_id) {
        return pds.deletePost(post_id);
    }

    @Override
    public List<Post> find(String keyword) {

        List<Post> list = new ArrayList<>();
        list = pds.getAllPost();
        List<Post> result = new ArrayList<>();
        keyword = keyword.toLowerCase();
        for (Post obj : list) {
            String strPost = obj.getPost_id() + " " + obj.getTitle() + " " + obj.getContent() + " " + obj.getAddress() + " " + obj.getCity() + " " + obj.getVote() + " " + obj.getPrice() + " " + obj.getUser_id() + " " + obj.getStatus();
            strPost = strPost.toLowerCase();

            if (strPost.indexOf(keyword) != -1) {
                result.add(obj);
            }
        }
        return result;
    }

    @Override
    public List<Post> findByDate(Date created_date) {
        return pds.getPostByCreatedDate(created_date);
    }

}
